<template>
  <div>
    <h2 ref="title">{{ message }}</h2>
    <button @click="addContent">add</button>
  </div>
</template>

<script>
import { onUpdated, ref, nextTick } from "vue";
export default {
  setup() {
    const message = ref("哈哈哈哈哈哈哈哈");
    const title = ref(null);
    const addContent = () => {
      message.value += "哈哈哈哈哈哈哈哈";
      nextTick(() => {
        let offsetHeight = title.value.offsetHeight;
        console.log(offsetHeight);
      });
    };
    onUpdated(() => {
      // 这里打印不合适. 如果内容变了 高度不变就会执行很多次
      // let offsetHeight = title.value.offsetHeight;
      // console.log(offsetHeight);
    });
    return {
      message,
      addContent,
      title,
    };
  },
};
</script>

<style lang="scss" scoped>
h2 {
  width: 100px;
}
</style>